function insert_bb(tag_open, tag_close) {
e_field = document.getElementById('post');
if (tag_open == '>') {
if (window.getSelection) {
tag_open += window.getSelection().toString() + "\n";
} else if (document.getSelection) {
tag_open += document.getSelection() + "\n";
} else if (document.selection) {
tag_open += document.selection.createRange().text + "\n";
}
}
if (e_field.selectionStart != undefined) {
// Work with selected text
e_field.focus();
        var string = e_field.value;
        var start_selection = e_field.selectionStart;
        var end_selection = e_field.selectionEnd - start_selection;
        e_field.value = string.substr(0, start_selection)
                 + tag_open
                 + string.substr(start_selection, end_selection)
                 + tag_close
                 + string.substr(start_selection + end_selection);
} else {
// Add tags to end of text
e_field.value += tag_open+tag_close;
}
}